'use strict';

const {
	dialog,
	app,
	BrowserWindow,
	ipcMain
} = require('electron')

var mainWindow = null;
var shadowWindow = null;
global.sharedObject = {
	shadowOn: false,
	title: "",
	content: ""
  }
//1296 792
//1519 844

//无边框定值 760
//测试用890
app.on('ready', function(){
	mainWindow = new BrowserWindow({
		width: 1519,
		height: 890,
		frame: true,
		resizable: false
	});
	mainWindow.loadURL('file://' + __dirname + '/static/index2.html');
	mainWindow.openDevTools();
	mainWindow.on('close', function () {
		mainWindow = null;
	});
});


ipcMain.on('quit-program', function () {
	app.quit();
});

//打开影子通道
ipcMain.on('shadow-on', function () {
	//隐藏主窗口
	mainWindow.hide();
	//加载影子通道窗口
	shadowWindow = new BrowserWindow({
		width: 1519,
		height: 890,
		frame: false,
		alwaysOnTop: true,
		transparent: true,
		resizable: false
	});
	global.sharedObject.shadowOn = true;
	shadowWindow.loadURL('file://' + __dirname + '/static/shadow.html');
	//shadowWindow.openDevTools();

	shadowWindow.on('closed', function () {
		shadowWindow = null;
		global.sharedObject.shadowOn = false;
		mainWindow.show();
		//影子通道关闭时，重新加载输入框的内容
		mainWindow.webContents.send('reload');
	});
});

ipcMain.on('minimize-shadow',function () {
	shadowWindow.minimize();
});

ipcMain.on('minimize-program', function(){
	mainWindow.minimize();
});

